package trastienda.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import trastienda.excepcion.DAOExcepcion;
import trastienda.modelo.Rol;


@Repository
public class RolDAOImpl implements RolDAO{

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	@SuppressWarnings(value = "unchecked")
    public Collection<Rol> listarTodos() throws DAOExcepcion {
            
            String sql = "select rol_nombre, descripcion from rol";

            RowMapper mapper = new RowMapper() {
                    public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                            Rol vo = new Rol();
                            vo.setRolNombre("rol_nombre");
                            vo.setDescripcion("descripcion");
                            
                            return vo;
                    }
            };
            return jdbcTemplate.query(sql, mapper);
    }

}
